package com.example.login

import android.view.LayoutInflater
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.databinding.BindingAdapter
import androidx.navigation.findNavController
import com.example.lib_common_ui.AnimUtils
import com.example.login.utils.ViewUtils

class LgClickEvent {
    /**
     * 输入框右边删除按钮点击
     * 清空手机号
     */
    @BindingAdapter("clearPhone")
    fun clearPhone(view: View, viewModel: LgLoginViewModel){
        viewModel.clearPhoneNumber()
    }

    /**
     * 输入框右边删除按钮点击
     * 清空手机号
     */
    @BindingAdapter("login")
    fun login(view:View, viewModel: LgLoginViewModel){
        val phone = viewModel.phoneNumber.value
        if (phone == null || phone.length != 11){
            AnimUtils.startSwingAnimation(view)
            ViewUtils.showAlert(view.context,"手机号应为11位数字",true)
            return
        }

        //用户是否同意协议
        if (!viewModel.isChecked.value!!) { //没有同意
            viewModel.agreementShouldSwing.postValue(true)
            ViewUtils.showAlert(view.context,"同意协议后继续",true)
            return
        }

        //跳转到下一个界面
        view.findNavController().navigate(R.id.action_lgPhoneFragment_to_lgVerifyFragment)
    }

    /**
     * 同意协议的按钮点击事件
     */
    @BindingAdapter("changeSelectState")
    fun changeSelectState(view: View, viewModel: LgLoginViewModel){
        viewModel.isChecked.postValue(!viewModel.isChecked.value!!)
    }
}

